package edu.misaka.moe.dao;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import org.junit.Test;

import edu.misaka.moe.dao.iface.NativeDao;
import edu.misaka.moe.domain.Native;
import edu.misaka.moe.utils.JdbcTemplate;

public class NativeDaoImpl implements NativeDao{
		

		@Override
		@Test
		public List<Native> getLevel1() {
			String sql="select * from nativePlace where length(code)=2";
			List<Native> list0=new ArrayList<>();
			List<Native> list=JdbcTemplate.query(sql, (rs)->{
				try {
					while(rs.next()) {
						Native nat=new Native(rs.getInt(1),rs.getString(2),rs.getString(3),false);
						list0.add(nat);
					}
				} catch (SQLException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
				return list0;
			}, new Object[] {});
			list.add(0,new Native(0,"请选择省份","00",false));
			System.out.println("NativeDaoImpl输出省级城市");
			for(Native a:list) {
				System.out.println(a.getId()+a.getName());
			}
			return list;
		}

		@Override
		public List<Native> getLevel2(String code) {
			String sql="select * from nativePlace where length(code)=4 and substr(code,1,2)=?";
			List<Native> list0=new ArrayList<>();
			List<Native> list=JdbcTemplate.query(sql, (rs)->{
				try {
					while(rs.next()) {
						Native nat=new Native(rs.getInt(1),rs.getString(2),rs.getString(3),false);
						list0.add(nat);
					}
				} catch (SQLException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
				return list0;
			}, new Object[] {code});
			return list;
			
		}
		
}
